/*
 * This file is part of ksPlatform
 * 
 * Copyright (c) 2014-2015
 * 
 * This file is dual-licensed under the AGPLv3 (http://www.gnu.org/licenses/agpl-3.0.html) 
 * 
 * If you are unsure which license is appropriate for your use, please contact the sales department
 * at 97041437@qq.com.
 */

package cn.com.ksplatform.modules.system.auth.permitmanager.service;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import cn.com.ksplatform.base.service.BaseService;
import cn.com.ksplatform.modules.system.auth.buttonmanager.service.PlatButtonService;
import cn.com.ksplatform.modules.system.auth.menumanager.service.PlatMenuService;
import cn.com.ksplatform.modules.system.auth.resourcemanager.service.PlatResourceService;
import cn.com.ksplatform.modules.system.auth.rolemanager.model.PlatRole;

/**
 * @ClassName:PermitService <br/>
 * @deprecated:TODO. <br/>
 * @Date: 2015年6月23日 上午10:55:03 <br/>
 * 
 * @author Mr.Luoxing
 * @version 1.0
 */
@Repository("system.modules.system.PermitService")
public class PermitService extends BaseService {
	
	@Autowired
	PlatMenuService menuService;
	
	@Autowired
	PlatButtonService buttonService;
	
	@Autowired
	PlatResourceService resourceService;
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public List findStations(String staId) {
		String hql = "select u from PlatUser u right join u.stations as s where s.staId = ? ";
		List values = new ArrayList();
		values.add(staId);
		List list = (List) this.findAll(hql, values);
		return list;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public List findUsers(String roleId) {
		String hql = "select u from PlatUser u right join u.roles as s where s.roleId = ? ";
		List values = new ArrayList();
		values.add(roleId);
		List list = (List) this.findAll(hql, values);
		return list;
	}
	
	public List findMenus(String roleId){
		Set<PlatRole> roles = new HashSet<PlatRole>();
		PlatRole pr = new PlatRole();
		pr.setRoleId(roleId);
		roles.add(pr);
		return menuService.getMenus(roles);
	}
	
	public List findBtns(String roleId,String btnGId){
		Set<PlatRole> roles = new HashSet<PlatRole>();
		PlatRole pr = new PlatRole();
		pr.setRoleId(roleId);
		roles.add(pr);
		return buttonService.getButtons(roles,btnGId);
	}
	
	public List findRes(String roleId,String menuId){
		Set<PlatRole> roles = new HashSet<PlatRole>();
		PlatRole pr = new PlatRole();
		pr.setRoleId(roleId);
		roles.add(pr);
		return resourceService.getRess(roles,menuId);
	}
}
